import { Moment } from 'moment';
import { UploadFile } from 'antd/lib/upload/interface';
import { parseDepartmentByFileList, setDefaultDepartment } from './departmentInfoFileHandle';
import { forcedAlignment, setOfficialHolidays } from './store';
import { parseWorkerByFileList } from './workerInfoFileHandler';
import { parseAttendanceRecordByFileList } from './attendanceRecordFilehandler';

export interface Info {
    departmentInfoFileList: UploadFile[];
    workerInfoFileList: UploadFile[];
    attendanceDataFileList: UploadFile[];
    clockMoment: [Moment, Moment];
    lateAndEarlyMoment: [Moment, Moment];
    officialHolidays: number;
}

export default function parseInfoMain(info: Info): Promise<void> {
    return new Promise((resolve, reject) => {
        setDefaultDepartment(info.clockMoment, info.lateAndEarlyMoment);
        setOfficialHolidays(info.officialHolidays);
        parseDepartmentByFileList(info.departmentInfoFileList).then(() => {
            parseWorkerByFileList(info.workerInfoFileList).then(() => {
                parseAttendanceRecordByFileList(info.attendanceDataFileList).then(() => {
                    forcedAlignment();
                    resolve()
                }, reject);
            }, reject);
        }, reject);
    });
}

